import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-14
 * Time: 23:32
 */
//https://leetcode.cn/problems/happy-number/
public class Test {
    public static boolean isHappy(int n) {
        HashSet<Integer> set=new HashSet<>();
        set.add(n);
        int sum=n;
        int x;
        while(n!=1){
            sum=0;
            while(n>0){
                x=n%10;
                n=n/10;
                sum=sum+x*x;
            }
            if(set.contains(sum)){
                return false;
            }
            else{
                set.add(sum);
            }
            n=sum;
        }
        return true;
    }
    public static void main(String[] args) {
        System.out.println(isHappy(2));
    }
}
